﻿using Microsoft.AspNetCore.Mvc;
using NUglify.Helpers;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaterCloud.Code;
using WaterCloud.DataBase;
using WaterCloud.Domain.Entity.STZBManage;

namespace WaterCloud.Service.STZBManage
{
    /// <summary>
    /// 武器详情服务类
    /// </summary>
    public class WeaponsInfo_Service : BaseService<WeaponsInfo>, IDenpendency
    {
        public WeaponsInfo_Service(ISqlSugarClient context) : base(context)
        {
        }


        /// <summary>
        /// 获取武器详情列表
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="keyword">关键词</param>
        /// <param name="level">武器层级</param>
        /// <returns></returns>
        public async Task<List<WeaponsInfo>> Get_WeaponsInfo_GridJson(SoulPage<WeaponsInfo> pagination, string keyword, int level)
        {
            var data = repository.IQueryable()
                .WhereIF(!string.IsNullOrEmpty(keyword), x => x.Name.Contains(keyword))
                .WhereIF(level > 0, x => x.Level == level);
            //权限过滤（保证分页参数存在）
            data = GetDataPrivilege("x", "", data);
            return await data.ToPageListAsync(pagination);
        }

        /// <summary>
        /// 删除武器详情数据
        /// </summary>
        /// <param name="ids">数据id</param>
        /// <returns></returns>
        public async Task Delete_WeaponsInfo(int[] ids)
        {
            await repository.Delete(x => ids.Contains(x.Id));
        }

        /// <summary>
        /// 添加武器信息
        /// </summary>
        /// <param name="weaponsInfo">信息</param>
        /// <returns></returns>
        public async Task Add_WeaponsInfo( WeaponsInfo weaponsInfo) => await repository.Insert(weaponsInfo);


        /// <summary>
        /// 批量添加武器信息
        /// </summary>
        /// <param name="lists">数据集合</param>
        /// <returns></returns>
        public async Task AddList_WeaponsInfo(List<WeaponsInfo> lists)
        {
            lists.ForEach(x => { x.CreateTime = DateTime.Now; });
            await repository.Insert(lists);
        }

        /// <summary>
        /// 根据id获取武器详情数据
        /// </summary>
        /// <param name="id">数据id</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public async Task<List<WeaponsInfo>> Get_Weapons_GridJson(SoulPage<WeaponsInfo> pagination, string id, int type)
        {
            var data = repository.IQueryable()
                .Where(x => x.F_Id == id)
                .WhereIF(type > 0, x => x.Level == type);
            //权限过滤（保证分页参数存在）
            data = GetDataPrivilege("x", "", data);
            return await data.ToPageListAsync(pagination);
        }
    }
}
